package com.ycsj.goldmedalnewconcept.activity;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

import com.google.gson.Gson;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.FormEncodingBuilder;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.squareup.picasso.Picasso;
import com.ycsj.goldmedalnewconcept.bean.ScoreDetailResponse;
import com.ycsj.goldmedalnewconcept.bean.ScoreDetailResponse.ScoreDetail;
import com.ycsj.goldmedalnewconcept.constant.Constant;
import com.ycsj.goldmedalnewconcept.utils.SPUtil;
import com.ycsj.goldmedalnewconcept.R;

//成绩查询（家长端）
public class ScoreQueryDetailActivity extends Activity implements OnClickListener {

	private ImageView iv_back;
	private Intent intent;
	private ListView lv_gonggao;
	private int position;
	private String role;
	private String account;
	private String tagid;
	private String userclass;
	private String userid;
	private String name;
	private GongaoInfoAdapter mAdapter;
	private List<ScoreDetail> scorelist;
	private List<String> imglist;
	private TextView tv_score;
	private TextView title;
	private TextView tv_time;
	private TextView tv_content;
	private String content;
	private String score;
	private String pic1;
	private String pic2;
	private String pic3;
	private String pic4;
	private String pic5;
	private String pic6;
	private String pic7;
	private String pic8;
	private String pic9;

	
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_scoredetail); 
		role = SPUtil.getString(this, "role", "");
		account = SPUtil.getString(this, "account", "");

		intent = getIntent();
		content = intent.getStringExtra("content");
		score = intent.getStringExtra("score");
		pic1 = intent.getStringExtra("pic1");
		pic2 = intent.getStringExtra("pic2");
		pic3 = intent.getStringExtra("pic3");
		pic4 = intent.getStringExtra("pic4");
		pic5 = intent.getStringExtra("pic5");
		pic6 = intent.getStringExtra("pic6");
		pic7 = intent.getStringExtra("pic7");
		pic8 = intent.getStringExtra("pic8");
		pic9 = intent.getStringExtra("pic9");
		imglist = new ArrayList<String>();
		initpic();
		initView();
		setOnListener();
		initData();
	}

	private void initpic() {
		// TODO Auto-generated method stub
		if(pic1!=null&&!"".equals(pic1)){
			imglist.add(pic1);
		}
		if(pic2!=null&&!"".equals(pic2)){
			imglist.add(pic2);
		}if(pic3!=null&&!"".equals(pic3)){
			imglist.add(pic3);
		}
		if(pic4!=null&&!"".equals(pic4)){
			imglist.add(pic4);
		}
		if(pic5!=null&&!"".equals(pic5)){
			imglist.add(pic5);
		}
		if(pic6!=null&&!"".equals(pic6)){
			imglist.add(pic6);
		}
		if(pic7!=null&&!"".equals(pic7)){
			imglist.add(pic7);
		}
		if(pic8!=null&&!"".equals(pic8)){
			imglist.add(pic8);
		}
		if(pic9!=null&&!"".equals(pic9)){
			imglist.add(pic9);
		}
	}

	private void initView() {
		// TODO Auto-generated method stub
		iv_back = (ImageView) findViewById(R.id.iv_back);
		lv_gonggao = (ListView) findViewById(R.id.lv_gonggao);
		title = (TextView) findViewById(R.id.title);
		
		if(name!=null&&!"".equals(name)){
			title.setText(name+"的成绩");
		}
		
		
		View headerView = LayoutInflater.from(getBaseContext()).inflate(
				R.layout.scoredetail_header, null);
		tv_score = (TextView) headerView.findViewById(R.id.tv_score);
		tv_content = (TextView) headerView.findViewById(R.id.tv_content);

		lv_gonggao.addHeaderView(headerView);
		
		// View view =
		// lv_gonggao.addHeaderView();

		// lv_gonggao.setAdapter(adapter);
	}

	private void initData() {

		mAdapter = new GongaoInfoAdapter();
		runOnUiThread(new Runnable() {
			@Override
			public void run() {
				tv_score.setText("测试分数："+score);
				tv_content.setText(content);

				lv_gonggao.setAdapter(mAdapter);
			}
		});
	}

	private void setOnListener() {
		// TODO Auto-generated method stub
		iv_back.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.iv_back:
			finish();
			break;

		}
	}

	class GongaoInfoAdapter extends BaseAdapter {

		public int getCount() {

			return imglist.size();
		}

		public Object getItem(int position) {

			return null;
		}

		public long getItemId(int position) {

			return 0;
		}

		ViewHolder vh = null;

		@Override
		public View getView(final int position, View convertView,
				ViewGroup parent) {
			if (convertView == null) {
				convertView = View.inflate(parent.getContext(),
						R.layout.item_gonggaodetail, null);
				vh = new ViewHolder();

				vh.iv_img = (ImageView) convertView.findViewById(R.id.iv_img);

				convertView.setTag(vh);
			} else {
				vh = (ViewHolder) convertView.getTag();
			}

			// if(gonggaolist.get(position).user_picture1!=null){
			//
			// Picasso.with(GonggaoActivity.this)
			// .load(gonggaolist.get(position).user_picture1).into(vh.iv_img);
			// }else{
			// vh.iv_img.setVisibility(vh.iv_img.GONE);
			// }
			Picasso.with(ScoreQueryDetailActivity.this)
					.load(imglist.get(position)).into(vh.iv_img);

			return convertView;
		}

		class ViewHolder {
			private ImageView iv_img;

		}
	}

}
